using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Magiq.Insert {
    public class InsertIntoQueryable<TFrom, TDestination, TNew> : IQueryableInsert<TFrom, TDestination, TNew> where TDestination : class {

        public InsertIntoQueryable(IQueryable<TFrom> queryable, Expression<Func<TFrom, TNew>> newValueExpression, IEnumerable<TDestination> destination) {
            Destination = destination;
            Source = queryable;
            NewExpression = newValueExpression;
        }

        #region IQueryableInsertBuilder<TSource,TNew> Members

        public Expression<Func<TFrom, TNew>> NewExpression { get; private set; }

        public IQueryable<TFrom> Source { get; private set; }

     

        public IEnumerable<TDestination> Destination { get; private set; }

        #endregion

        public int Execute() {
            var provider = Magiq.For(Source, Destination).GetInsertProvider();
            return provider.Execute(this);
        }
    }
}